package com.kotasoft.iip.processor;

import java.math.BigDecimal;
import java.math.RoundingMode;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kotasoft.iip.model.insurance.Order;
import com.kotasoft.iip.model.interfaces.HasOrder;

public class FeesProcessor implements Processor {

	private static final Logger LOG = LoggerFactory.getLogger(FeesProcessor.class);

	public void process(Exchange exchange) throws Exception {
		LOG.debug("Procesando gastos");
		Order order = exchange.getIn().getMandatoryBody(HasOrder.class).getOrder();
		BigDecimal amount = order.getAmount();
		BigDecimal percent = new BigDecimal("1");
		BigDecimal fees = amount.multiply(percent).divide(new BigDecimal("100"), 2, RoundingMode.HALF_EVEN);
		BigDecimal netAmount = amount.subtract(fees);
		order.setNetAmount(netAmount);
	}
}
